package com.lagou.edu.service.impl;

import com.lagou.edu.annotation.ZbAutowired;
import com.lagou.edu.annotation.ZbService;
import com.lagou.edu.annotation.ZbTransanctional;
import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.TransferService;


/**
 * @author 应癫
 */
@ZbService("transferService")
public class TransferServiceImpl implements TransferService {

    @ZbAutowired
    private AccountDao accountDao;


    @ZbTransanctional
    @Override
    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
            System.out.println("accountdao:" + accountDao);
            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);

            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);

            accountDao.updateAccountByCardNo(to);
//            int c = 1/0;
            accountDao.updateAccountByCardNo(from);

    }

    @Override
    public String toString() {
        return "TransferServiceImpl{" +
                "accountDao=" + accountDao +
                '}';
    }
}
